package com.sky.controller.user;

import com.sky.constant.MessageConstant;
import com.sky.dto.DrugDTO;
import com.sky.dto.DrugPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DrugService;
import com.sky.vo.DrugDetailVO;
import com.sky.vo.ListResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "用户端药品相关接口")
@RequestMapping("/user/drug")
public class DrugController {
    @Autowired
    private DrugService drugService;

    @GetMapping("/list")
    @ApiOperation("用户端查询药品列表")
    public Result<PageResult> list(DrugPageQueryDTO queryDTO) {
        log.info("前期请求：{}", queryDTO);
        PageResult pageResult = drugService.list(queryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("用户端通过药品id查询药品详情")
    public Result<DrugDetailVO> detail(@PathVariable("id") Long id) {
        log.info("用户端查询药品详情: {}", id);
        DrugDetailVO drugDetailVOList = drugService.detail(id);
        return Result.success(drugDetailVOList);
    }

    @PostMapping("/add")
    @ApiOperation("药品信息添加")
    public Result<String> add(@RequestBody DrugDTO drugDTO) {
        log.info("用户端添加药品信息: {}", drugDTO);
        drugService.add(drugDTO);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除药品")
    public Result<String> delete(@PathVariable("id") Long id) {
        log.info("用户端删除药品: {}", id);
        drugService.delete(id);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @PutMapping("/update")
    @ApiOperation("修改药品信息")
    public Result<String> update(@RequestBody DrugDTO drugDTO) {
        log.info("用户端修改药品信息: {}", drugDTO);
        drugService.update(drugDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }
}
